import request from '@/utils/request';
import { OrgItem } from './data.d';

export async function list(params: any) {
  const user = JSON.parse(localStorage.getItem('user-detail') || '{}')
  if(user.tenants && user.tenants[0]){
    return request(`/AllLinks/dimensionnew/_query/tree`, {
      method: 'GET',
      params,
    });
  }else{
    return request(`/AllLinks/dimension/_query/tree`, {
      method: 'GET',
      params,
    });
  }
}

export async function remove(id: string) {
  const user = JSON.parse(localStorage.getItem('user-detail') || '{}')
  if(user.tenants && user.tenants[0]){
    return request(`/AllLinks/dimensionnew/${id}`, {
      method: 'DELETE',
    });
  }else{
    return request(`/AllLinks/dimension/${id}`, {
      method: 'DELETE',
    });
  }
}

export async function add(params: OrgItem) {
  const user = JSON.parse(localStorage.getItem('user-detail') || '{}')
  if(user.tenants && user.tenants[0]){
    return request(`/AllLinks/dimensionnew`, {
      method: 'POST',
      data: params,
    });
  }else{
    return request(`/AllLinks/dimension`, {
      method: 'POST',
      data: params,
    });
  }
}
export async function saveOrUpdate(params: OrgItem) {
  const user = JSON.parse(localStorage.getItem('user-detail') || '{}')
  if(user.tenants && user.tenants[0]){
    return request(`/AllLinks/dimensionnew`, {
      method: 'PATCH',
      data: params,
    });
  }else{
    return request(`/AllLinks/dimension/${params.id}`, {
      method: 'PUT',
      data: params,
    });
  }
}

export async function bindUser(params: any) {
  return request(`/AllLinks/dimension-user/_query/no-paging`, {
    method: 'GET',
    params,
  });
}

export async function unBindUser(id: string) {
  return request(`/AllLinks/dimension-user/${id}`, {
    method: 'DELETE',
  });
}

export async function bind(params: any) {
  return request(`/AllLinks/dimension-user`, {
    method: 'POST',
    data: params,
  });
}
